package com.telit.firecommand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.firecommand.dao.CadPlotAttachmentDao;
import com.telit.firecommand.entity.CadPlotAttachment;
import com.telit.firecommand.service.ICadPlotAttachmentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 联动标绘详情表 服务实现类
 * </p>
 *
 * @author yummy
 * @since 2021-07-31
 */
@Service
@Transactional
public class CadPlotAttachmentServiceImpl extends ServiceImpl<CadPlotAttachmentDao, CadPlotAttachment> implements
        ICadPlotAttachmentService {

    @Override
    public int add(CadPlotAttachment cadPlotAttachment) {
        return baseMapper.insert(cadPlotAttachment);
    }

    @Override
    public int delete(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public List<Integer> deleteBatch(Integer[] ids) {
        List<Integer> values = new ArrayList<Integer>();
        if (ids != null && ids.length > 0) {
            for (Integer id : ids) {
                values.add(delete(id));
            }
        }
        return values;
    }

    @Override
    public int updateData(CadPlotAttachment cadPlotAttachment) {
        return baseMapper.updateById(cadPlotAttachment);
    }

    @Override
    public CadPlotAttachment findById(Integer id) {
        return baseMapper.selectById(id);
    }


    @Override
    public IPage<CadPlotAttachment> findListByPage(CadPlotAttachment cadPlotAttachment, Integer page,
                                                   Integer pageCount) {
        IPage<CadPlotAttachment> cadPlotAttachmentPage = new Page<>(page, pageCount);
        QueryWrapper<CadPlotAttachment> wrapper = new QueryWrapper<>();
        if (cadPlotAttachment != null) {
            if (StringUtils.hasText(cadPlotAttachment.getFillColor())) {
                wrapper.eq("fill_color", cadPlotAttachment.getFillColor());
            }
            if (StringUtils.hasText(cadPlotAttachment.getBorderColor())) {
                wrapper.eq("border_color", cadPlotAttachment.getBorderColor());
            }
            if (StringUtils.hasText(cadPlotAttachment.getBorderWidth())) {
                wrapper.eq("border_width", cadPlotAttachment.getBorderWidth());
            }
            if (StringUtils.hasText(cadPlotAttachment.getImageRgba())) {
                wrapper.eq("image_rgba", cadPlotAttachment.getImageRgba());
            }
            if (StringUtils.hasText(cadPlotAttachment.getContent())) {
                wrapper.eq("content", cadPlotAttachment.getContent());
            }
        }
        return baseMapper.selectPage(cadPlotAttachmentPage, wrapper);
    }

    @Override
    public List<CadPlotAttachment> searchNoPage(CadPlotAttachment cadPlotAttachment) {
        QueryWrapper<CadPlotAttachment> wrapper = new QueryWrapper<>();
        if (cadPlotAttachment != null) {
            if (StringUtils.hasText(cadPlotAttachment.getFillColor())) {
                wrapper.eq("fill_color", cadPlotAttachment.getFillColor());
            }
            if (StringUtils.hasText(cadPlotAttachment.getBorderColor())) {
                wrapper.eq("border_color", cadPlotAttachment.getBorderColor());
            }
            if (StringUtils.hasText(cadPlotAttachment.getBorderWidth())) {
                wrapper.eq("border_width", cadPlotAttachment.getBorderWidth());
            }
            if (StringUtils.hasText(cadPlotAttachment.getImageRgba())) {
                wrapper.eq("image_rgba", cadPlotAttachment.getImageRgba());
            }
            if (StringUtils.hasText(cadPlotAttachment.getContent())) {
                wrapper.eq("content", cadPlotAttachment.getContent());
            }
        }
        return baseMapper.selectList(wrapper);
    }

}
